import {
    createRouter,
    createWebHistory
} from 'vue-router'

const routes = [{
    path: '/',
    redirect: '/login'
},
{
    path: '/login',
    name: 'Login',
    component: () => import('../views/Login.vue')
},
{
    path: '/main',
    name: 'Main',
    redirect: '/home',
    component: () => import('../views/Main.vue'),
    children: [{
        path: '/home',
        name: 'Home',
        component: () => import('../views/Home.vue'),
        meta: [{
            name: '首页',
            url: '/home'
        }, {
            name: '网站统计'
        }]
    }, {
        path: '/notice',
        name: 'notice',
        component: () => import('../views/notice/index.vue'),
    }, {
        path: '/addNotice',
        name: 'addNotice',
        component: () => import('../views/notice/add.vue'),
    }, {
        path: '/teacher',
        name: 'teacher',
        component: () => import('../views/teacher/index.vue'),
    }, {
        path: '/teacher/add',
        name: 'teacherAdd',
        component: () => import('../views/teacher/add.vue'),
    }, {
        path: '/editNotice/:id',
        name: 'editNotice',
        component: () => import('../views/notice/edit.vue'),
    }, {
        path: '/teacher/edit/:id',
        name: 'editteacher',
        component: () => import('../views/teacher/edit.vue'),
    }, {
        path: '/orders',
        name: 'orders',
        component: () => import('../views/orders.vue'),
    }, {
        path: '/paper_detail',
        name: 'paper_detail',
        component: () => import('../views/paper_detail.vue'),
    }, {
        path: '/system',
        name: 'System',
        component: () => import('../views/System.vue'),
        meta: [{
            name: '系统',
            url: '/system'
        }, {
            name: '系统设置'
        }]
    }, {
        path: '/work',
        name: 'Work',
        component: () => import('../views/Work.vue'),
        meta: [{
            name: '首页',
            url: '/home'
        }, {
            name: '模块路径'
        }]
    }, {
        path: '/user',
        name: 'User',
        component: () => import('../views/User.vue'),
        meta: [{
            name: '模块',
            url: '/user'
        }, {
            name: '用户管理'
        }]
    }, {
        path: '/guideType',
        name: 'GuideType',
        component: () => import('../views/GuideType/GuideType.vue'),
        meta: [{
            name: '模块',
            url: '/user'
        }, {
            name: '办事指南',
            url: '/guide'
        }, {
            name: '指南分类'
        }]
    }, {
        path: '/addGuideType',
        name: 'AddGuideType',
        component: () => import('../views/GuideType/Add.vue'),
        meta: [{
            name: '模块',
            url: '/user'
        }, {
            name: '办事指南',
            url: '/guide'
        }, {
            name: '指南分类',
            url: '/guideType'
        }, {
            name: '添加分类',
        }]
    }, {
        path: '/editGuideType/:id',
        name: 'EditGuideType',
        component: () => import('../views/GuideType/Edit.vue'),
        meta: [{
            name: '模块',
            url: '/user'
        }, {
            name: '办事指南',
            url: '/guide'
        }, {
            name: '指南分类',
            url: '/guideType'
        }, {
            name: '编辑分类',
        }]
    }, {
        path: '/guide',
        name: 'Guide',
        component: () => import('../views/Guide/Guide.vue'),
        meta: [{
            name: '模块',
            url: '/user'
        }, {
            name: '办事指南',
            url: '/guide'
        }, {
            name: '指南管理'
        }]
    }, {
        path: '/addGuide',
        name: 'AddGuide',
        component: () => import('../views/Guide/Add.vue'),
        meta: [{
            name: '模块',
            url: '/user'
        }, {
            name: '办事指南',
            url: '/guide'
        }, {
            name: '指南管理',
            url: '/guide'
        }, {
            name: '添加指南',
        }]
    }, {
        path: '/editGuide/:id',
        name: 'EditGuide',
        component: () => import('../views/Guide/Edit.vue'),
        meta: [{
            name: '模块',
            url: '/user'
        }, {
            name: '办事指南',
            url: '/guide'
        }, {
            name: '指南管理',
            url: '/guide'
        }, {
            name: '编辑指南'
        }]
    }, {
        path: '/book',
        name: 'Book',
        component: () => import('../views/Book.vue'),
        meta: [{
            name: '模块',
            url: '/user'
        }, {
            name: '办事指南',
            url: '/guide'
        }, {
            name: '预约管理',
        }]
    }, {
        path: '/seekType',
        name: 'SeekType',
        component: () => import('../views/SeekType/SeekType.vue'),
        meta: [{
            name: '模块',
            url: '/user'
        }, {
            name: '办事指南',
            url: '/guide'
        }, {
            name: '咨询分类',
        }]
    }, {
        path: '/addSeekType',
        name: 'AddSeekType',
        component: () => import('../views/SeekType/Add.vue'),
        meta: [{
            name: '模块',
            url: '/user'
        }, {
            name: '办事指南',
            url: '/guide'
        }, {
            name: '咨询分类',
            url: '/seekType',
        }, {
            name: '添加分类'
        }]
    }, {
        path: '/editSeekType/:id',
        name: 'EditSeekType',
        component: () => import('../views/SeekType/Edit.vue'),
        meta: [{
            name: '模块',
            url: '/user'
        }, {
            name: '办事指南',
            url: '/guide'
        }, {
            name: '咨询分类',
            url: '/seekType',
        }, {
            name: '编辑分类'
        }]
    }, {
        path: '/seek',
        name: 'Seek',
        component: () => import('../views/Seek.vue'),
        meta: [{
            name: '模块',
            url: '/user'
        }, {
            name: '办事指南',
            url: '/guide'
        }, {
            name: '指南管理'
        }]
    }, {
        path: '/grid',
        name: 'Grid',
        component: () => import('../views/Grid/Grid.vue'),
        meta: [{
            name: '模块',
            url: '/user'
        }, {
            name: '网格管理',
        }]
    }, {
        path: '/addGrid',
        name: 'AddGrid',
        component: () => import('../views/Grid/Add.vue'),
        meta: [{
            name: '模块',
            url: '/user'
        }, {
            name: '网格管理',
            url: '/grid'
        }, {
            name: '添加网格'
        }]
    }, {
        path: '/editGrid/:id',
        name: 'EditGrid',
        component: () => import('../views/Grid/Edit.vue'),
        meta: [{
            name: '模块',
            url: '/user'
        }, {
            name: '网格管理',
            url: '/grid'
        }, {
            name: '编辑网格'
        }]
    }, {
        path: '/office',
        name: 'Office',
        component: () => import('../views/Office/Office.vue'),
        meta: [{
            name: '模块',
            url: '/user'
        }, {
            name: '两委管理'
        }]
    }, {
        path: '/addOffice',
        name: 'AddOffice',
        component: () => import('../views/Office/Add.vue'),
        meta: [{
            name: '模块',
            url: '/user'
        }, {
            name: '两委管理',
            url: '/office'
        }, {
            name: '添加委员'
        }]
    }, {
        path: '/editOffice/:id',
        name: 'EditOffice',
        component: () => import('../views/Office/Edit.vue'),
        meta: [{
            name: '模块',
            url: '/user'
        }, {
            name: '两委管理',
            url: '/office'
        }, {
            name: '编辑委员'
        }]
    }, {
        path: '/partyType',
        name: 'PartyType',
        component: () => import('../views/PartyType/PartyType.vue'),
        meta: [{
            name: '模块',
            url: '/user'
        }, {
            name: '党建管理',
            url: '/party'
        }, {
            name: '党建分类',
        }]
    }, {
        path: '/addPartyType',
        name: 'AddPartyType',
        component: () => import('../views/PartyType/Add.vue'),
        meta: [{
            name: '模块',
            url: '/user'
        }, {
            name: '党建管理',
            url: '/party'
        }, {
            name: '党建分类',
            url: '/partyType'
        }, {
            name: '添加分类',
        }]
    }, {
        path: '/editPartyType/:id',
        name: 'EditPartyType',
        component: () => import('../views/PartyType/Edit.vue'),
        meta: [{
            name: '模块',
            url: '/user'
        }, {
            name: '党建管理',
            url: '/party'
        }, {
            name: '党建分类',
            url: '/partyType'
        }, {
            name: '编辑分类',
        }]
    }, {
        path: '/party',
        name: 'Party',
        component: () => import('../views/Party/Party.vue'),
        meta: [{
            name: '模块',
            url: '/user'
        }, {
            name: '党建管理',
            url: '/party'
        }, {
            name: '党建信息'
        }]
    }, {
        path: '/addParty',
        name: 'AddParty',
        component: () => import('../views/Party/Add.vue'),
        meta: [{
            name: '模块',
            url: '/user'
        }, {
            name: '党建管理',
            url: '/party'
        }, {
            name: '党建信息',
            url: '/party'
        }, {
            name: '添加信息',
        }]
    }, {
        path: '/editParty/:id',
        name: 'EditParty',
        component: () => import('../views/Party/Edit.vue'),
        meta: [{
            name: '模块',
            url: '/user'
        }, {
            name: '党建管理',
            url: '/party'
        }, {
            name: '党建信息',
            url: '/party'
        }, {
            name: '编辑信息',
        }]
    }, {
        path: '/active',
        name: 'Active',
        component: () => import('../views/Active/Active.vue'),
        meta: [{
            name: '模块',
            url: '/user'
        }, {
            name: '社区动态'
        }]
    }, {
        path: '/addActive',
        name: 'AddActive',
        component: () => import('../views/Active/Add.vue'),
        meta: [{
            name: '模块',
            url: '/user'
        }, {
            name: '社区动态',
            url: '/active'
        }, {
            name: '添加动态',
        }]
    }, {
        path: '/editActive/:id',
        name: 'EditActive',
        component: () => import('../views/Active/Edit.vue'),
        meta: [{
            name: '模块',
            url: '/user'
        }, {
            name: '社区动态',
            url: '/active'
        }, {
            name: '编辑动态',
        }]
    }, {
        path: '/tenancy',
        name: 'Tenancy',
        component: () => import('../views/Tenancy/Tenancy.vue'),
        meta: [{
            name: '模块',
            url: '/user'
        }, {
            name: '房屋租卖'
        }]
    }, {
        path: '/addTenancy',
        name: 'AddTenancy',
        component: () => import('../views/Tenancy/Add.vue'),
        meta: [{
            name: '模块',
            url: '/user'
        }, {
            name: '房屋租卖',
            url: '/tenancy'
        }, {
            name: '添加信息'
        }]
    }, {
        path: '/editTenancy/:id',
        name: 'EditTenancy',
        component: () => import('../views/Tenancy/Edit.vue'),
        meta: [{
            name: '模块',
            url: '/user'
        }, {
            name: '房屋租卖',
            url: '/tenancy'
        }, {
            name: '编辑信息'
        }]
    }, {
        path: '/bannerHome',
        name: 'BannerHome',
        component: () => import('../views/Banner/Home.vue'),
        meta: [{
            name: '系统',
            url: '/system'
        }, {
            name: '轮播图',
            url: '/bannerHome'
        }, {
            name: '首页轮播图'
        }]
    }, {
        path: '/bannerGuide',
        name: 'BannerGuide',
        component: () => import('../views/Banner/Guide.vue'),
        meta: [{
            name: '系统',
            url: '/system'
        }, {
            name: '轮播图',
            url: '/bannerGuide'
        }, {
            name: '指南轮播图'
        }]
    }, {
        path: '/bannerParty',
        name: 'BannerParty',
        component: () => import('../views/Banner/Party.vue'),
        meta: [{
            name: '系统',
            url: '/system'
        }, {
            name: '轮播图',
            url: '/bannerParty'
        }, {
            name: '党建轮播图'
        }]
    }, {
        path: '/nav',
        name: 'Nav',
        component: () => import('../views/Nav/Nav.vue'),
        meta: [{
            name: '系统',
            url: '/system'
        }, {
            name: '导航设置'
        }]
    }, {
        path: '/addNav',
        name: 'AddNav',
        component: () => import('../views/Nav/Add.vue'),
        meta: [{
            name: '系统',
            url: '/system'
        }, {
            name: '导航设置',
            url: '/nav'
        }, {
            name: '添加导航'
        }]
    }, {
        path: '/editNav/:id',
        name: 'EditNav',
        component: () => import('../views/Nav/Edit.vue'),
        meta: [{
            name: '系统',
            url: '/system'
        }, {
            name: '导航设置',
            url: '/nav'
        }, {
            name: '编辑导航'
        }]
    }, {
        path: '/template',
        name: 'Template',
        component: () => import('../views/Template.vue'),
        meta: [{
            name: '系统',
            url: '/system'
        }, {
            name: '模板消息'
        }]
    }, {
        path: '/suggest',
        name: 'Suggest',
        component: () => import('../views/Suggest.vue'),
        meta: [{
            name: '系统',
            url: '/system'
        }, {
            name: '投诉意见'
        }]
    }, {
        path: '/manager',
        name: 'Manager',
        component: () => import('../views/Manager/Manager.vue'),
        meta: [{
            name: '系统',
            url: '/system'
        }, {
            name: '管理中心'
        }]
    }, {
        path: '/addManager',
        name: 'AddManager',
        component: () => import('../views/Manager/Add.vue'),
        meta: [{
            name: '系统',
            url: '/system'
        }, {
            name: '管理中心',
            url: '/system'
        }, {
            name: '添加管理',
        }]
    }, {
        path: '/editManager/:id',
        name: 'EditManager',
        component: () => import('../views/Manager/Edit.vue'),
        meta: [{
            name: '系统',
            url: '/system'
        }, {
            name: '管理中心',
            url: '/system'
        }, {
            name: '编辑管理'
        }]
    }]
}, {
    path: '/404',
    name: '404',
    component: () => import('../views/404.vue')
},
]

const router = createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes
})

router.beforeEach((to, from, next) => {
    document.title = '论文管理系统'
    const token = sessionStorage.getItem('token')
    if (to.path == "/login") {
        if (!token) {
            return next()
        } else {
            return next('/main')
        }
    } else {
        if (!token) {
            return next('/login')
        } else {
            if (to.matched.length === 0) {
                next('/404')
            }
            next()
        }
    }
})

export default router